<?php
$maxpag=15;
if (!isset($pag)) {
     $pag=1;
}
$neto=FuncNeto($NumMov);
$desde = (($pag-1)*$maxpag);
$grid1 = new psa_dina_grid;
$grid1->sql      = "Select * from movimientos where Numero='$NumMov' order by id desc";
$grid1->sql2     = "Select count(*) from movimientos where Numero='$NumMov'";
$grid1->desde    = 4;
$grid1->procesa  = "mod/caja/agrega.php?psa_modulo=mod/caja/prueba.php&NumMov=$NumMov";
$grid1->cantidad = $maxpag;
$grid1->linkbar  = "index.php?psa_modulo=mod/caja/prueba.php&NumMov=$NumMov";
$grid1->pagbar   = $pag;

$form1 = new psa_formulario;
$form1->formulario = "form1";
$form1->ejecuta = "mod/caja/agrega.php?psa_modulo=mod/caja/prueba.php&NumMov=$NumMov";
$form1->alineacion = "center";

$form1->additem("Cantidad", 0);
$form1->additem("", 1, "cantidad", "", "onKeyDown=\"if(event.keyCode==13) event.keyCode=9;\"");
$form1->additem("Codigo", 0);
$form1->additem("", 1, "codigo");
$form1->additem("", 3, "boton","Agrega");

$tab1        = new psa_tabla;
$tab1->borde = 0;
$tab1->ancho = "100%";
$tab1->alineacion = "center";
$tab1->masfila( 2);
$tab1->dato( 1, $form1 );
       $tab2 = new psa_tabla;
       $tab2->borde = 0;
       $tab2->ancho = "100%";
       $tab2->alineacion = "center";
       $tab2->masfila( 2);
       $tab2->dato( 1, "Neto:");
       $tab2->dato( 2, "$".number_format($neto, 0, ',', '.'),"right");
       $tab2->masfila( 2);
       $tab2->dato( 1, "Iva:");
       $tab2->dato( 2, "$".number_format(($neto*IVA), 0, ',', '.'),"right");
       $tab2->masfila( 2);
       $tab2->dato( 2, "<hr>","right");
       $tab2->masfila( 2);
       $tab2->dato( 1, "Total:");
       $tab2->dato( 2, "<font size=6><strong>$".number_format(($neto*(1+IVA)), 0, ',', '.')."</strong></font>","right");
$tab1->dato( 2, $tab2);
$tab1->masfila( 2);
$tab1->dato( 1, "<hr>");
$tab1->dato( 2, "<hr>");
$tab1->masfila( 2);
$tab1->dato( 1, $grid1 );
       $form2 = new psa_formulario;
       $form2->formulario = "form2";
       $form2->ejecuta = "mod/caja/cierra.php?psa_modulo=&NumMov=$NumMov";
       $form2->alineacion = "center";

       $form2->additem("", 3, "boton","Cerrar Transaccion");
$tab1->dato( 2, $form2,"center" );
$tab1->muestra();
echo "             <script language=\"JavaScript\">\n";
echo "            <!--\n";
echo "                  document.form1.cantidad.focus();\n";
echo "            //-->\n";
echo "            </script>\n";

function FuncNeto($NumMov){
   $Salida=0;
   $link = mysql_connect("localhost","root","");
   mysql_select_db("inventario",$link);
   $sql = "Select * from movimientos where Numero=$NumMov";
   $result = mysql_query($sql,$link);
   if ($row = mysql_fetch_array($result)){
        do{
           $sql2 = "Select * from productos where Codigo='".$row["codigo"]."'";
           $result2 = mysql_query($sql2,$link);
           if ($row2 = mysql_fetch_array($result2)){
              $Salida=$Salida+($row["cantidad"]*$row2["PrecioVenta"]);
           }
        } while ($row = mysql_fetch_array($result));
   }
   return($Salida);
}
?>